package com.zy.framework.util;

import com.zy.common.constant.PermissionConstants;
import com.zy.common.utils.StringUtils;

/**
 * @program: zhengyang
 * @author: LuoXin
 * @create: 2018-12-20 22:49
 * @description: permission 权限工具类
 */

public class PermissionUtils
{
    /**
     * 权限错误消息提醒
     *
     * @param permissionsStr
     * @return
     */
    public static String getMsg(String permissionsStr)
    {
        String permission = StringUtils.substringBetween("[", "]");
        String msg = MessageUtils.message("no.view.permission", permission);
        if (StringUtils.endsWithIgnoreCase(permissionsStr, PermissionConstants.ADD_PERMISSION))
        {
            msg = MessageUtils.message("no.create.permission", permission);
        }
        else if (org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EDIT_PERMISSION))
        {
            msg = MessageUtils.message("no.update.permission", permission);
        }
        else if (org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(permission, PermissionConstants.REMOVE_PERMISSION))
        {
            msg = MessageUtils.message("no.delete.permission", permission);
        }
        else if (org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EXPORT_PERMISSION))
        {
            msg = MessageUtils.message("no.export.permission", permission);
        }
        else if (org.apache.commons.lang3.StringUtils.endsWithAny(permission,
                new String[]{PermissionConstants.VIEW_PERMISSION, PermissionConstants.LIST_PERMISSION}))
        {
            msg = MessageUtils.message("no.view.permission", permission);
        }
        return msg;
    }
}
